package com.nkzy;

import com.nkzy.servlet.SecondServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@ServletComponentScan // 可以扫描到Servlet，也可以扫描到Filter
@RestController
public class Demospringboot09Application {

    public static void main(String[] args) {
        SpringApplication.run(Demospringboot09Application.class, args);
    }

    @GetMapping("/runMain")
    public String runMain(){
        return "这是运行在启动类的控制器呦";
    }

    @Bean
    public ServletRegistrationBean getServletBean(){
        ServletRegistrationBean bean = new ServletRegistrationBean(new SecondServlet());
        // 设置访问路径
        bean.addUrlMappings("/secondServlet");
        return bean;
    }

}
